// 全局配置
config = {
    mode: "run",	// 运行环境（run：生产环境 | debug：开发环境）
    qiniu: {        // 适用于包含七牛存储的插件
        bucket_url: "http://cdn.gexinit.com/",                    // 七牛存储空间地址
        token_url: "/api/qiniu",                                 // 七牛令牌生成地址
        flash_url: "/static/plug/qn_jssdk/plupload/Moxie.swf"    // 插件 flash 地址，用于PC浏览器低版本，注意路径
    },
    folder: {
        cate_add_url: "/system/plug/file/api/cate_add",   // 创建分组（名称：name）
        cate_del_url: "/system/plug/file/api/cate_del",   // 删除分组（分组ID：cid | 模式：mode -- 删除全部：all、仅删除分组：cate）
        cate_edit_url: "/system/plug/file/api/cate_edit",  // 修改分组名称（分组ID：cid | 名称：name）
        cate_list_url: "/system/plug/file/api/getCateList",  // 分组列表（无参数）
        file_add_url: "/system/plug/file/api/upfile",   // 上传文件（分组ID：cate | 地址：url | 名称：name | 宽度：width | 高度：height | 大小：size | 类型：type）
        file_del_url: "/system/plug/file/api/file_del",   // 删除文件（文件ID：files -- 多个文件以逗号隔开）
        file_edit_url: "/system/plug/file/api/file_edit",  // 修改文件分组（分组ID：cid | 文件ID：files -- 多个文件以逗号隔开）
        file_list_url: "/system/plug/file/api/file_list"   // 文件列表（分组ID：cid | 文件类型：type | 分页：page | 每页数量：size）
    }
};
//公共的JS
var gx = {};
gx.loadFile = function (filename, filetype) {
    if (filetype == "js") { // 判断文件类型
        var fileref = document.createElement('script')// 创建标签
        fileref.setAttribute("type", "text/javascript")// 定义属性type的值为text/javascript
        fileref.setAttribute("src", filename)// 文件的地址
    } else if (filetype == "css") { // 判断文件类型
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

gx.iframeindex = null;
//弹出toast提示信息
gx.toast = function (msg, callback) {
    layer.msg(msg, function () {
        if (typeof (callback) != "undefined") {
            callback();
        }
    })

};

//弹出信息框的
gx.alert = function (text, title, icon) {
    layer.open({
        title: typeof (title) == "undefined" ? '提示信息' : title,
        icon: typeof (icon) == "undefined" ? 0 : icon,
        content: text
    });
}

//显示图片预览的  可以多张
gx.photos = function (title, img) {
    var sp = img.split(",");
    var temp = "";
    for (var i = 0; i < sp.length; i++) {
        if (i == sp.length - 1) {
            temp = temp + '{"alt": "' + title + '","pid": 1, "src": "' + sp[i] + '", "thumb": ""}';
        } else {
            temp = temp + '{"alt": "' + title + '","pid": 1, "src": "' + sp[i] + '", "thumb": ""},';
        }
    }
    var json = '{"title": "' + title + '","id":123, "start": 0, "data": [' + temp + ']}'
    json = JSON.parse(json)
    layer.ready(function () {
        layer.photos({photos: json});
    });
}

gx.alerts = function (text, callback, icon) {
    layer.alert(text, {icon: typeof (icon) == "undefined" ? 0 : icon}, function () {
        if (typeof (callback) != "undefined") {
            callback();
        }
    });
}

gx.load = function () {
    layer.load(0, {shade: [0.5, '#B2B5B7']});
}
gx.confirm = function (text, callback) {
    var index = layer.confirm(text, {icon: 3, title: '询问'}, function (index) {
        layer.close(index);
        callback();
    });

}

gx.iframeAuto = function () {
    layer.iframeAuto(gx.iframeindex);
}
gx.closewin = function () {
    layer.close(gx.iframeindex);
}
gx.open = function (title, html) {
    layer.open({
        type: 1,
        title: title,
        closeBtn: 1,
        shadeClose: true,
        content: html
    });
}
gx.win = function (title, url, areas) {
    gx.iframeindex = layer.open({
        type: 2,
        title: title,
        shadeClose: true,
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        shade: 0.8,
        area: typeof (areas) == "undefined" ? ['50%', '50%'] : areas,
        content: url //iframe的url
    });
}

//发送ajax 请求的
gx.ajax = function (url, callback, error) {
    $.ajax({
        url: url,
        type: "get",
        //	timeout : 30,
        dataType: "json",
        success: function (ret) {
            callback(ret);
        },
        error: function () {
            if (typeof (error) != "undefined") {
                error();
            }
        }
    });
}


gx.postdata = function (url, data, callback, error) {
    $.ajax({
        url: url,
        type: "post",
        //timeout : 30,
        data: data,
        dataType: "json",
        success: function (ret) {
            callback(ret);
        },
        error: function () {
            if (typeof (error) != "undefined") {
                error();
            }
        }
    });
}
gx.post = function (url, form, callback, error) {
    $.ajax({
        url: url,
        type: "post",
        //timeout : 30,
        data: $("#" + form).serialize(),
        dataType: "json",
        success: function (ret) {
            callback(ret);
        },
        error: function () {
            if (typeof (error) != "undefined") {
                error();
            }
        }
    });
}


localdata = {
    set: function (key, val) {
        val = (typeof val == "object") ? JSON.stringify(val) : val;
        localStorage.setItem(key, val);
    },
    get: function (key, datatype) {
        if (typeof datatype == "undefined")
            return localStorage.getItem(key);
        else
            return JSON.parse(localStorage.getItem(key));
    },
    del: function (key) {
        localStorage.removeItem(key);
    }
};
//获取浏览器的参数
gx.paramem = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}
gx.del = function (url) {
    gx.confirm("你是否确定删除这条信息？", function () {
        gx.ajax(url, function (d) {
            if (d.state == true) {
                window.location.reload();
            } else {
                gx.alert(d.msg);
            }

        })
    })
}
$(window).load(function () {
    $('#status').delay(300).fadeOut();
    $('#preloader').delay(300).fadeOut('slow');
})
/*! layPage-v1.3.0 分页组件 License MIT  http://laypage.layui.com/ By 贤心 */
;!function () {
    "use strict";

    function a(d) {
        var e = "laypagecss";
        a.dir = "dir" in a ? a.dir : f.getpath + "/skin/laypage.css", new f(d), a.dir && !b[c](e)
    }

    a.v = "1.3";
    var b = document, c = "getElementById", d = "getElementsByTagName", e = 0, f = function (a) {
        var b = this, c = b.config = a || {};
        c.item = e++, b.render(!0)
    };
    f.on = function (a, b, c) {
        return a.attachEvent ? a.attachEvent("on" + b, function () {
            c.call(a, window.even)
        }) : a.addEventListener(b, c, !1), f
    }, f.getpath = function () {
        var a = document.scripts, b = a[a.length - 1].src;
        return b.substring(0, b.lastIndexOf("/") + 1)
    }(), f.use = function (c, e) {
        var f = b.createElement("link");
        f.type = "text/css", f.rel = "stylesheet", f.href = a.dir, e && (f.id = e), b[d]("head")[0].appendChild(f), f = null
    }, f.prototype.type = function () {
        var a = this.config;
        return "object" == typeof a.cont ? void 0 === a.cont.length ? 2 : 3 : void 0
    }, f.prototype.view = function () {
        var b = this, c = b.config, d = [], e = {};
        if (c.pages = 0 | c.pages, c.curr = 0 | c.curr || 1, c.groups = "groups" in c ? 0 | c.groups : 5, c.first = "first" in c ? c.first : "&#x9996;&#x9875;", c.last = "last" in c ? c.last : "&#x5C3E;&#x9875;", c.prev = "prev" in c ? c.prev : "&#x4E0A;&#x4E00;&#x9875;", c.next = "next" in c ? c.next : "&#x4E0B;&#x4E00;&#x9875;", c.pages <= 1) return "";
        for (c.groups > c.pages && (c.groups = c.pages), e.index = Math.ceil((c.curr + (c.groups > 1 && c.groups !== c.pages ? 1 : 0)) / (0 === c.groups ? 1 : c.groups)), c.curr > 1 && c.prev && d.push('<a href="javascript:;" class="laypage_prev" data-page="' + (c.curr - 1) + '">' + c.prev + "</a>"), e.index > 1 && c.first && 0 !== c.groups && d.push('<a href="javascript:;" class="laypage_first" data-page="1"  title="&#x9996;&#x9875;">' + c.first + "</a><span>&#x2026;</span>"), e.poor = Math.floor((c.groups - 1) / 2), e.start = e.index > 1 ? c.curr - e.poor : 1, e.end = e.index > 1 ? function () {
            var a = c.curr + (c.groups - e.poor - 1);
            return a > c.pages ? c.pages : a
        }() : c.groups, e.end - e.start < c.groups - 1 && (e.start = e.end - c.groups + 1); e.start <= e.end; e.start++) e.start === c.curr ? d.push('<span class="laypage_curr" ' + (/^#/.test(c.skin) ? 'style="background-color:' + c.skin + '"' : "") + ">" + e.start + "</span>") : d.push('<a href="javascript:;" data-page="' + e.start + '">' + e.start + "</a>");
        return c.pages > c.groups && e.end < c.pages && c.last && 0 !== c.groups && d.push('<span>&#x2026;</span><a href="javascript:;" class="laypage_last" title="&#x5C3E;&#x9875;"  data-page="' + c.pages + '">' + c.last + "</a>"), e.flow = !c.prev && 0 === c.groups, (c.curr !== c.pages && c.next || e.flow) && d.push(function () {
            return e.flow && c.curr === c.pages ? '<span class="page_nomore" title="&#x5DF2;&#x6CA1;&#x6709;&#x66F4;&#x591A;">' + c.next + "</span>" : '<a href="javascript:;" class="laypage_next" data-page="' + (c.curr + 1) + '">' + c.next + "</a>"
        }()), '<div name="laypage' + a.v + '" class="laypage_main laypageskin_' + (c.skin ? function (a) {
            return /^#/.test(a) ? "molv" : a
        }(c.skin) : "default") + '" id="laypage_' + b.config.item + '">' + d.join("") + function () {
            return c.skip ? '<span class="laypage_total"><label>&#x5230;&#x7B2C;</label><input type="number" min="1" onkeyup="this.value=this.value.replace(/\\D/, \'\');" class="laypage_skip"><label>&#x9875;</label><button type="button" class="laypage_btn">&#x786e;&#x5b9a;</button></span>' : ""
        }() + "</div>"
    }, f.prototype.jump = function (a) {
        if (a) {
            for (var b = this, c = b.config, e = a.children, g = a[d]("button")[0], h = a[d]("input")[0], i = 0, j = e.length; j > i; i++) "a" === e[i].nodeName.toLowerCase() && f.on(e[i], "click", function () {
                var a = 0 | this.getAttribute("data-page");
                c.curr = a, b.render()
            });
            g && f.on(g, "click", function () {
                var a = 0 | h.value.replace(/\s|\D/g, "");
                a && a <= c.pages && (c.curr = a, b.render())
            })
        }
    }, f.prototype.render = function (a) {
        var d = this, e = d.config, f = d.type(), g = d.view();
        2 === f ? e.cont.innerHTML = g : 3 === f ? e.cont.html(g) : b[c](e.cont).innerHTML = g, e.jump && e.jump(e, a), d.jump(b[c]("laypage_" + e.item)), e.hash && !a && (location.hash = "!" + e.hash + "=" + e.curr)
    }, "function" == typeof define ? define(function () {
        return a
    }) : "undefined" != typeof exports ? module.exports = a : window.laypage = a
}();
//模板组件
;!function () {
    "use strict";
    var f, b = {open: "{{", close: "}}"}, c = {
        exp: function (a) {
            return new RegExp(a, "g")
        }, query: function (a, c, e) {
            var f = ["#([\\s\\S])+?", "([^{#}])*?"][a || 0];
            return d((c || "") + b.open + f + b.close + (e || ""))
        }, escape: function (a) {
            return String(a || "").replace(/&(?!#?[a-zA-Z0-9]+;)/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&#39;").replace(/"/g, "&quot;")
        }, error: function (a, b) {
            var c = "Laytpl Error：";
            return "object" == typeof console && console.error(c + a + "\n" + (b || "")), c + a
        }
    }, d = c.exp, e = function (a) {
        this.tpl = a
    };
    e.pt = e.prototype, e.pt.parse = function (a, e) {
        var f = this, g = a, h = d("^" + b.open + "#", ""), i = d(b.close + "$", "");
        a = a.replace(/[\r\t\n]/g, " ").replace(d(b.open + "#"), b.open + "# ").replace(d(b.close + "}"), "} " + b.close).replace(/\\/g, "\\\\").replace(/(?="|')/g, "\\").replace(c.query(), function (a) {
            return a = a.replace(h, "").replace(i, ""), '";' + a.replace(/\\/g, "") + '; view+="'
        }).replace(c.query(1), function (a) {
            var c = '"+(';
            return a.replace(/\s/g, "") === b.open + b.close ? "" : (a = a.replace(d(b.open + "|" + b.close), ""), /^=/.test(a) && (a = a.replace(/^=/, ""), c = '"+_escape_('), c + a.replace(/\\/g, "") + ')+"')
        }), a = '"use strict";var view = "' + a + '";return view;';
        try {
            return f.cache = a = new Function("d, _escape_", a), a(e, c.escape)
        } catch (j) {
            return delete f.cache, c.error(j, g)
        }
    }, e.pt.render = function (a, b) {
        var e, d = this;
        return a ? (e = d.cache ? d.cache(a, c.escape) : d.parse(d.tpl, a), b ? (b(e), void 0) : e) : c.error("no data")
    }, f = function (a) {
        return "string" != typeof a ? c.error("Template not found") : new e(a)
    }, f.config = function (a) {
        a = a || {};
        for (var c in a) b[c] = a[c]
    }, f.v = "1.1", "function" == typeof define ? define(function () {
        return f
    }) : "undefined" != typeof exports ? module.exports = f : window.laytpl = f
}();


//Eric


// Ajax.web.1.0.5（闪店定制版）
// 作者 : Eric（远八格）
// 来源 : hhtools.web.js
// 日期 : 2016-07-22

// 更新 : 请求成功或者失败，关闭 确认弹窗（confirm）、输入弹窗（prompt）

function Ajax(url, data, success, failed) {
    // 两种调用方式：
    // GET  -- Ajax(url,success,failed);
    // POST -- Ajax(url,postdata,success,failed);

    // 6 中可能的情况：
    // 1,n,n,n
    // 1,2,n,n
    // 1,2,3,n
    // 1,2,3,4
    // 1,n,2,n
    // 1,n,3,4

    var param = {};
    param.url = url;
    param.data = "";
    param.type = "get";
    param.success = function (ret) {
        if (!ret.state) layer.msg(ret.msg);
    };
    param.failed = function (ret) {
        layer.confirm("网络异常，是否重新加载？", {
            yes: function () {
                location.reload(true);
            },
            cancel: function () {
                history.back();
            }
        });
    };

    switch (arguments.length) {
        case 2:
            if (typeof (arguments[1]) != "function") {
                param.type = "post";
                param.data = arguments[1];
            } else
                param.success = arguments[1];
            break;
        case 3:
            if (typeof (arguments[1]) != "function") {
                param.type = "post";
                param.data = arguments[1];
                param.success = arguments[2];
            } else {
                param.success = arguments[1];
                param.failed = arguments[2];
            }
            break;
        case 4:
            param.type = "post";
            param.data = arguments[1];
            param.success = arguments[2];
            param.failed = arguments[3];
            break;
    }

    // 显示加载提示
    layer.load();

    $.ajax({
        url: param.url,
        type: param.type,
        data: param.data,
        dataType: "json",
        success: function (ret) {
            layer.closeAll("loading");
            param.success(ret);
            Console("Ajax Return : ", ret);
        },
        error: function () {
            layer.closeAll("loading");
            param.failed();
        }
    });

}

function Alert(val) {
    var ret = "";

    if (arguments.length == 0)
        ret = "未填写参数";
    else
        for (i = 0; i < arguments.length; i++) {
            str = arguments[i];
            ret += (typeof (str) == "object") ? JSON.stringify(str) : str;
        }

    alert(ret);
}


function Console(val) {
    var ret = "";

    if (arguments.length == 0)
        ret = "未填写参数";
    else
        for (i = 0; i < arguments.length; i++) {
            str = arguments[i];
            ret += (typeof (str) == "object") ? JSON.stringify(str) : str;
        }

    console.log(ret);
}


/* lazyload 图片懒加载  https://github.com/jieyou/lazyload */
!function (a) {
    "function" == typeof define && define.amd ? define(["jquery"], a) : a(window.jQuery || window.Zepto)
}(function (a, b) {
    function g() {
    }

    function h(a, b) {
        var e;
        return e = b._$container == d ? ("innerHeight" in c ? c.innerHeight : d.height()) + d.scrollTop() : b._$container.offset().top + b._$container.height(), e <= a.offset().top - b.threshold
    }

    function i(b, e) {
        var f;
        return f = e._$container == d ? d.width() + (a.fn.scrollLeft ? d.scrollLeft() : c.pageXOffset) : e._$container.offset().left + e._$container.width(), f <= b.offset().left - e.threshold
    }

    function j(a, b) {
        var c;
        return c = b._$container == d ? d.scrollTop() : b._$container.offset().top, c >= a.offset().top + b.threshold + a.height()
    }

    function k(b, e) {
        var f;
        return f = e._$container == d ? a.fn.scrollLeft ? d.scrollLeft() : c.pageXOffset : e._$container.offset().left, f >= b.offset().left + e.threshold + b.width()
    }

    function l(a, b) {
        var c = 0;
        a.each(function (d, e) {
            function g() {
                f.trigger("_lazyload_appear"), c = 0
            }

            var f = a.eq(d);
            if (!(f.width() <= 0 && f.height() <= 0 || "none" === f.css("display"))) if (b.vertical_only) if (j(f, b)) ; else if (h(f, b)) {
                if (++c > b.failure_limit) return !1
            } else g(); else if (j(f, b) || k(f, b)) ; else if (h(f, b) || i(f, b)) {
                if (++c > b.failure_limit) return !1
            } else g()
        })
    }

    function m(a) {
        return a.filter(function (b, c) {
            return !a.eq(b)._lazyload_loadStarted
        })
    }

    function n(a, b) {
        function h() {
            f = 0, g = +new Date, e = a.apply(c, d), c = null, d = null
        }

        var c, d, e, f, g = 0;
        return function () {
            c = this, d = arguments;
            var a = new Date - g;
            return f || (a >= b ? h() : f = setTimeout(h, b - a)), e
        }
    }

    var f, c = window, d = a(c), e = {
        threshold: 0,
        failure_limit: 0,
        event: "scroll",
        effect: "show",
        effect_params: null,
        container: c,
        data_attribute: "src",
        data_srcset_attribute: "original-srcset",
        skip_invisible: !0,
        appear: g,
        load: g,
        vertical_only: !1,
        check_appear_throttle_time: 300,
        url_rewriter_fn: g,
        no_fake_img_loader: !1,
        placeholder_data_img: "",
        placeholder_real_img: "http://ditu.baidu.cn/yyfm/lazyload/0.0.1/img/placeholder.png"
    };
    f = function () {
        var a = Object.prototype.toString;
        return function (b) {
            return a.call(b).replace("[object ", "").replace("]", "")
        }
    }(), a.fn.hasOwnProperty("lazyload") || (a.fn.lazyload = function (b) {
        var i, j, k, h = this;
        return a.isPlainObject(b) || (b = {}), a.each(e, function (g, h) {
            -1 != a.inArray(g, ["threshold", "failure_limit", "check_appear_throttle_time"]) ? "String" == f(b[g]) ? b[g] = parseInt(b[g], 10) : b[g] = h : "container" == g ? (b.hasOwnProperty(g) ? b[g] == c || b[g] == document ? b._$container = d : b._$container = a(b[g]) : b._$container = d, delete b.container) : !e.hasOwnProperty(g) || b.hasOwnProperty(g) && f(b[g]) == f(e[g]) || (b[g] = h)
        }), i = "scroll" == b.event, k = 0 == b.check_appear_throttle_time ? l : n(l, b.check_appear_throttle_time), j = i || "scrollstart" == b.event || "scrollstop" == b.event, h.each(function (c, d) {
            var e = this, f = h.eq(c), i = f.attr("src"), k = f.attr("data-" + b.data_attribute),
                l = b.url_rewriter_fn == g ? k : b.url_rewriter_fn.call(e, f, k),
                n = f.attr("data-" + b.data_srcset_attribute), o = f.is("img");
            return 1 == f._lazyload_loadStarted || i == l ? (f._lazyload_loadStarted = !0, void (h = m(h))) : (f._lazyload_loadStarted = !1, o && !i && f.one("error", function () {
                f.attr("src", b.placeholder_real_img)
            }).attr("src", b.placeholder_data_img), f.one("_lazyload_appear", function () {
                function i() {
                    d && f.hide(), o ? (n && f.attr("srcset", n), l && f.attr("src", l)) : f.css("background-image", 'url("' + l + '")'), d && f[b.effect].apply(f, c ? b.effect_params : []), h = m(h)
                }

                var d, c = a.isArray(b.effect_params);
                f._lazyload_loadStarted || (d = "show" != b.effect && a.fn[b.effect] && (!b.effect_params || c && 0 == b.effect_params.length), b.appear != g && b.appear.call(e, f, h.length, b), f._lazyload_loadStarted = !0, b.no_fake_img_loader || n ? (b.load != g && f.one("load", function () {
                    b.load.call(e, f, h.length, b)
                }), i()) : a("<img />").one("load", function () {
                    i(), b.load != g && b.load.call(e, f, h.length, b)
                }).attr("src", l))
            }), void (j || f.on(b.event, function () {
                f._lazyload_loadStarted || f.trigger("_lazyload_appear")
            })))
        }), j && b._$container.on(b.event, function () {
            k(h, b)
        }), d.on("resize load", function () {
            k(h, b)
        }), a(function () {
            k(h, b)
        }), this
    })
});


